package com.mycinema.dao;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

/**
 * 分类数据库操作-工具类
 * @author panyingtao
 *
 */
public class MyBatisUtil {
	private static SqlSessionFactory factory;
	//静态块
	static{
		//加载配置文件
		InputStream in;
		try {
			in = Resources.getResourceAsStream("mybatis-config.xml");
			//创建session工厂
			 factory=new SqlSessionFactoryBuilder().build(in);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 创建session
	 * @return
	 */
	public static SqlSession openSession(){
		return factory.openSession();
	}
}
